#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    int T;
    cin >> T;
    int a, b, c, d;
    while(T--){
        cin >> a >> b >> c>> d;
        LL f1 = (LL)a * d, f2 = (LL)b * c;

        
        if(a == 0 ||c == 0){
            if(a == 0 && c == 0){
                cout << "0" << '\n';
            }else{
                cout << "1" << '\n';
            }
            continue;
        }

        if(f1 == f2){
            cout << "0" << '\n';
        }else if(f1 == 1 || f2 == 1){
            cout << "1" << '\n';
        }else if(f2 % f1 == 0 || f1 % f2 == 0){
            cout << "1" << '\n';
        }else{
            cout << "2" << '\n';
        }
    }



    return 0;
}